package com.nana.petadventure.ui.scene
{
	import com.nana.framework.ui.PSprite;
	
	import flash.events.Event;
	
	public class BackgroundLayer extends PSprite
	{
		public static const NEARVIEW_SPEED_COEFFICIENT:Number = 1;
		public static const MIDVIEW_SPEED_COEFFICIENT:Number = 0.5;
		public static const FARVIEW_SPEED_COEFFICIENT:Number = 0.2;
		
		private var _moveSpeed:Number = 0;
		private var _staticViewSprite:BackgroundSprite;
		private var _farViewSprite:BackgroundSprite;
		private var _midViewSprite:BackgroundSprite;
		private var _nearViewSprite:BackgroundSprite;
		
		public function BackgroundLayer()
		{
			super();
		}
		
		public function init():void {
			_staticViewSprite = new BackgroundSprite;
			this.addChild(_staticViewSprite);
			_farViewSprite = new BackgroundSprite;
			this.addChild(_farViewSprite);
			_midViewSprite = new BackgroundSprite;
			this.addChild(_midViewSprite);
			_nearViewSprite = new BackgroundSprite;
			this.addChild(_nearViewSprite);
		}
		
		public function start():void {
			this.addEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
		}
		
		public function stop():void {
			this.removeEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
		}
		
		private function enterFrameHandler(event:Event):void {
			// all sprites moving
			this.move();
		}
		
		private function move():void {
			_nearViewSprite.move(this.moveSpeed * NEARVIEW_SPEED_COEFFICIENT);
			_midViewSprite.move(this.moveSpeed * MIDVIEW_SPEED_COEFFICIENT);
			_farViewSprite.move(this.moveSpeed * FARVIEW_SPEED_COEFFICIENT);
		}

		public function get moveSpeed():Number
		{
			return _moveSpeed;
		}

		public function set moveSpeed(value:Number):void
		{
			_moveSpeed = value;
		}

	}
}